/*
* ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
* Without permission, no one has the right to obtain, disclose or use this software in any way.
*/

package ecarx.xsf.notificationcenter.model;

import android.util.Log;


import java.util.ArrayList;
import java.util.List;

import ecarx.xsf.notificationcenter.notification.INotificationBar;
import ecarx.xsf.notificationcenter.notification.IPendingIntentAction;
import ecarx.xsf.notificationcenter.sdk.IStatusBarAction;
import ecarx.xsf.notificationcenter.sdk.IStatusBarNotification;


public class BuildCompetition {

    private Competition competition;

    public Competition build() {
        return competition;
    }


    public BuildCompetition newBuilder(IStatusBarNotification notification) {
        competition = new Competition();
        competition.setCreateTime(System.currentTimeMillis());

        INotificationBar iNotificationBar =
                new INotificationBar(notification.getId(),notification.getPkgName(),
                        notification.getTitle(),
                        notification.getContent(),
                        notification.isTtsOn(),
                        notification.isSeeSay(),
                        notification.getSubStyle(),
                        notification.getTag(),
                        key(notification),
                        notification.getWhen(),
                        getActions(notification.getActions()),
                        getActions(notification.getSeeSayEventActions()));
        competition.setNotificationBar(iNotificationBar);

        Log.d("CompetitionStrategy", iNotificationBar.toString());
        return this;
    }

    private List<IPendingIntentAction> getActions(List<IStatusBarAction> actions) {
        List<IPendingIntentAction> actionList = new ArrayList<>();

        if (actions != null) {
            for (IStatusBarAction action : actions) {
                IPendingIntentAction pendingIntentAction = new IPendingIntentAction(
                        action.getId(),
                        action.getText(),
                        action.getBgUrl(),
                        action.getPendingIntent());
                actionList.add(pendingIntentAction);
            }
        }
        return actionList;
    }

    private String key(IStatusBarNotification notification){
        return notification.getId()+"|" +notification.getPkgName() + "|" +notification.getTag();
    }


}
